//
//  LSZHotVC.m
//  JK九酷云头条
//
//  Created by 九酷 on 2017/11/10.
//  Copyright © 2017年 LC. All rights reserved.
//

#import "LSZHotVC.h"

@interface LSZHotVC ()

@end

@implementation LSZHotVC

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"24小时热文";
    [self getDataDic];
    [self.tableViewHot registerClass:[LSZHotTableViewCell class] forCellReuseIdentifier:@"LSZHotTableViewCell"];
}
-(void)getDataDic
{
    [LSZRequestResolutionDic initWithHotRequestData:^(BOOL isOk, NSString * str, LSZHotManager * mg) {
        if (isOk == YES) {
            self.lszHotManager = mg;
            [self.tableViewHot reloadData];
        }else{
            NSString * string  = [NSString stringWithFormat:@"%@ ",rewen];
            [LSZCacheHandling initWithfindPlist:string :^(BOOL isOk, NSDictionary * diction) {
                if (isOk == YES) {
                    LSZHotManager * manager = [[LSZHotManager alloc]initWithHotManager:diction];
                    self.lszHotManager = manager;
                    [self.tableViewHot reloadData];
                }
                else{
                    [self setHubStr:str];
                }
            }];
        }
    }];
}
-(void)setHubStr :(NSString *)str
{
    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
    hud.mode = MBProgressHUDModeText;//枚举类型不同的效果
    //    hud.mode = MBProgressHUDModeCustomView;
    hud.label.text= [NSString stringWithFormat:@"%@",str];
    [self performSelector:@selector(hiddenMBAction) withObject:nil afterDelay:1.0];
}
-(void)hiddenMBAction
{
    [MBProgressHUD hideHUDForView:self.view animated:YES];
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 60;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.lszHotManager.mutDataArray.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    LSZHotTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"LSZHotTableViewCell" forIndexPath:indexPath];
    if (!cell) {
        cell = [[LSZHotTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"LSZHotTableViewCell"];
    }
    LSZHotMg * hotMg = nil;
    hotMg = self.lszHotManager.mutDataArray[indexPath.row];
    cell.labelTime.text =  [NSString stringWithFormat:@"%@",hotMg.uptime];
    cell.labelControl.text =  [NSString stringWithFormat:@"%@",hotMg.title];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    return cell;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    LSZHotMg * hotMg = nil;
    hotMg = self.lszHotManager.mutDataArray[indexPath.row];
    LSZVideoDetailsWebView * vc = [[LSZVideoDetailsWebView alloc]init];
    vc.url = hotMg.url;
    vc.titleStr = @"24小时热文";
    vc.isDistinguish = @"2";
    vc.strComeFrame = @"1";
    [self.navigationController pushViewController:vc animated:YES];
}
-(UITableView *)tableViewHot
{
    if (_tableViewHot == nil) {
        _tableViewHot = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, ScreenHeight) style:UITableViewStylePlain];
        _tableViewHot.delegate = self;
        _tableViewHot.dataSource = self;
//        _tableViewHot.appearance.estimatedRowHeight =0;
//        _tableViewHot.appearance.estimatedSectionFooterHeight =0;
//        _tableViewHot.appearance.estimatedSectionHeaderHeight =0;
        [self.view addSubview:_tableViewHot];
    }
    return _tableViewHot;
}

@end
